package com.administrator.cloudapplication.activitys;

import android.content.Intent;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.base.BaseActivity;
import com.administrator.cloudapplication.constant.Urls;
import com.bumptech.glide.Glide;

/**
 * 电子书的详情页面，只有自己写好的一个简单布局和一个WebView。
 */
public class EbookDetailActivity extends BaseActivity {
    WebView mWebView;
    ImageView ebook_cover;
    TextView ebook_name;
    TextView ebook_author;
    Button start_reading;

    private String author;
    private String bookname;
    private String bookthumb;
    private String url;
    private String id;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_ebook_more);
        mWebView = (WebView) findViewById(R.id.wv_ebook);
        ebook_cover = (ImageView) findViewById(R.id.ebook_cover);
        ebook_name = (TextView) findViewById(R.id.ebook_name);
        ebook_author = (TextView) findViewById(R.id.ebook_author);
        start_reading = (Button) findViewById(R.id.start_reading);
    }

    @Override
    protected void initData() {
        //获取到上个页面传过来的所有数据，显示到自己写的控件上。
        id = getIntent().getStringExtra("id");
        author = getIntent().getStringExtra("author");
        bookname = getIntent().getStringExtra("bookname");
        bookthumb = getIntent().getStringExtra("bookthumb");
        //获取到WebView的网址并加载出来。
        url = Urls.BASE_URL2 + Urls.BOOK_DETAILS + id;
        mWebView.loadUrl(url);
        ebook_name.setText(bookname);
        ebook_author.setText("作者：" + author);
        //上传图书的封面，图片路径由上个页面传过来。
        Glide.with(mContext).load(Urls.IMG_URL2 + bookthumb)
                .placeholder(R.mipmap.error).error(R.mipmap
                .error).into(ebook_cover);
        //点击开始阅读按钮，点击后跳转到一个新的WebView，并将id和type传递过去
        start_reading.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(EbookDetailActivity.this, MedioDetailActivity.class);
                intent.putExtra("type", 2);
                intent.putExtra("vid", id);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onLeftClick() {
        finish();
    }

    @Override
    protected void onRightClick() {

    }


}
